﻿<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8" />
	<?php
	include('config.php');
	if(isset($_POST['submit'])){
		$surname=$_POST['surname'];
		$name=$_POST['name'];
		$pseudo=$_POST['pseudo'];

		$target_dir = "images/";
		$target_avatar = $target_dir . basename($_FILES["avatar"]["name"]);
		$uploadOk = 1;
		$avatarFileType = pathinfo($target_avatar,PATHINFO_EXTENSION);
		// Check if image file is a actual image or fake image
		// if(isset($_POST['submit'])) {
		//     $check = getimagesize($_FILES["avatar"]["tmp_name"]);
		//     if($check !== false) {
		//         $uploadOk = 1;
		//     } else {
		//         $uploadOk = 0;
		//     }
		// }
		// Check if file already exists
		if (file_exists($target_avatar)) {
		    echo "Sorry, file already exists.";
		    $uploadOk = 0;
		}
		// Check file size
		if ($_FILES["avatar"]["size"] > 10000000) {
		    echo "Sorry, your file is too large.";
		    $uploadOk = 0;
		}
		// Allow certain file formats
		if($avatarFileType != "jpg" && $avatarFileType != "png" && $avatarFileType != "jpeg"
		&& $avatarFileType != "gif" ) {
		    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
		    $uploadOk = 0;
		}
		// Check if $uploadOk is set to 0 by an error
		if ($uploadOk == 0) {
		    echo "Sorry, your file was not uploaded.";
		// if everything is ok, try to upload file
		} else {
		    if (move_uploaded_file($_FILES["avatar"]["tmp_name"], $target_avatar)) {
		        echo "The file ". basename( $_FILES["avatar"]["name"]). " has been uploaded.";
		    } else {
		        echo "Sorry, there was an error uploading your file.";
		    }
		}




		$target_dir = "music/";
		$target_music = $target_dir . basename($_FILES["music"]["name"]);
		$uploadMusic = 1;
		$imageFileType = pathinfo($target_music,PATHINFO_EXTENSION);
		// Check if file already exists
		if (file_exists($target_music)) {
		    echo "Sorry, MUSIC already exists.";
		    $uploadMusic = 0;
		}
		if(($_FILES["music"]["type"] != "audio/mp3")){
			echo "Sorry, your file type is incorrect";
		    $uploadMusic = 0;
		}

		// Check file size

		if ($_FILES["music"]["size"] > 10000000) {
		    echo "Sorry, your file is too large.";
		    $uploadMusic = 0;
		}
		// Check if $uploadOk is set to 0 by an error
		if ($uploadMusic == 0) {
		    echo "Sorry, your file was not uploaded.";
		// if everything is ok, try to upload file
		} else {
		    if (move_uploaded_file($_FILES["music"]["tmp_name"], $target_music)) {
		        echo $target_music. " has been uploaded.";
		    } 
			   else 
		        echo "Sorry, there was an error MUSIC uploading your file.";
		    }
		$videolink=$_POST['videolink'];
		$experience=$_POST['experience'];
		$age=$_POST['age'];
		$gender=$_POST['gender'];
		$city=$_POST['city'];
		$kazakh=$_POST['kazakh'];
		$russian=$_POST['russian'];
		$english=$_POST['english'];
		$category=$_POST['category'];
		$pricetill=$_POST['pricetill'];
		$aboutyou=$_POST['aboutyou'];
		$sql = "INSERT INTO artists (surname,name,pseudo,avatar,music,videolink,experience,age,gender,city,kazakh,russian,english,category,pricetill,aboutyou) VALUES ('$surname','$name','$pseudo','$target_avatar','$target_music','$videolink','$experience','$age','$gender','$city','$kazakh','$russian','$english','$category','$pricetill','$aboutyou')";
		if($uploadOk==1 && $uploadMusic==1){
			if (mysqli_query($conn, $sql)) {
		    echo "New record created successfully";
			} else {
			    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
			}
		}else{
			echo "Record didnot added";
		}
		
	}
	?>
</head>
<body>
	<form action="registerartist.php" method="POST" enctype="multipart/form-data">
	<table>
		<tr>
			<td>Surname</td><td><input type="text" name="surname"></td>
		</tr>
		<tr>
			<td>Name</td><td><input type="text" name="name"></td>
		</tr>
		<tr>
			<td>Pseudo</td><td><input type="text" name="pseudo"></td>
		</tr>
		<tr>
			<td>Avatar</td><td><input type="file" name="avatar" id="avatar"></td>
		</tr>
		<tr>
			<td>Music</td><td><input type="file" name="music" id="music"></td>		
		</tr>
		<tr>
			<td>Experience</td><td><input type="text" name="experience"></td>		
		</tr>
		<tr>
			<td>Date of birthday</td><td><input type="date" name="age"></td>		
		</tr>
		<tr>
			<td>gender</td><td><input type="radio" name="gender" value="Male" checked>Male
	<input type="radio" name="gender" value="Female">Female</td>		
		</tr>
		<tr>
			<td>City</td><td><input type="text" name="city"></td>		
		</tr>
		<tr>
			<td>Kazakh</td><td><select name="kazakh">
		<option>Off</option>
		<option>On</option>
		</td>		
		</tr>
		<tr>
			<td>Russian</td><td><select name="russian">
		<option>Off</option>
		<option>On</option></td>		
		</tr>
		<tr>
			<td>English</td><td><select name="english">
		<option>Off</option>
		<option>On</option></td>		
		</tr>
		<tr>
			<td>Category</td><td><select name="category">
		<option>Любитель</option>
		<option>Эстрада</option>
		</td>		
		</tr>
		<tr>
			<td>Pricetill</td><td><input type="text" name="pricetill"></td>		
		</tr>
		<tr>
			<td>About you</td><td><textarea name="aboutyou" cols="21.5"></textarea></td>
		</tr>
		<tr>
			<td>Video link</td><td><input type="text" name="videolink"></td>
		</tr>
	</table>
<input type="submit" value="add Actor" name="submit">
</form>
<button><a href="adminindex.php"/>Back</button>
</body>
</html>